package com.taobao.sinan.dal;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.taobao.sinan.dal.route.Route;

public class LogicTable {
	private String name;
	private Route route;
	private String suffix = "";
	private List<String> routeKey;
	private List<Table> tables;

	public LogicTable(String name, String suffix, Route route, List<String> routeKey, List<Table> tables) {
		this.name = name;
		this.route = route;
		this.suffix = suffix;
		this.routeKey = Collections.unmodifiableList(routeKey);

		Collections.sort(tables, new Comparator<Table>() {
			@Override
			public int compare(Table o1, Table o2) {
				return o1.getTbname().compareToIgnoreCase(o2.getTbname());
			}
		});

		this.tables = Collections.unmodifiableList(tables);
	}

	public String getName() {
		return name;
	}

	public Route getRoute() {
		return route;
	}

	public List<String> getRouteKey() {
		return routeKey;
	}

	public List<Table> getTables() {
		return tables;
	}

	public String getSuffix() {
		return suffix == null ? "" : suffix;
	}
}
